% by YLX 6/11
% Version 4.0
% Based on SBY's fQR.m
% calculating profit
function profit = function_fQR(Q, R)
	global I ci cI r % 主程序中定义
	Q_new = Q;
	R_new = R;
	cols = size(Q, 2);
	for n=1:cols
		Q_new(:, n) = r * (n - 1) * Q_new(:, n);
		R_new(:, n) = (n - 1) * R_new(:, n);
	end
		R_new = ci * R_new;
		R_new(I, :) = cI / ci * R_new(I, :);
	profit = sum(sum(Q_new)) - sum(sum(R_new));     
	return;


